package org.javaboy.vhr.service;

import org.javaboy.vhr.mapper.MenuRoleMapper;
import org.javaboy.vhr.mapper.RoleMapper;
import org.javaboy.vhr.model.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author Willie Chen
 * @Description
 * @Date 2019/12/22
 * @Param $param
 **/
@Service
public class RoleService {

    @Autowired
    RoleMapper roleMapper;
    @Autowired
    MenuRoleMapper menuRoleMapper;

    public List<Role> getALLRoles() {

     return   roleMapper.getALLRoles();
    }

    public Integer addRole(Role role) {
     if(!role.getName().startsWith("ROLE_")){

         role.setName("ROLE_"+role.getName());
     }
      return  roleMapper.insert(role);
    }

    public Integer deleteRoleById(Integer rid) {

        menuRoleMapper.deleteByRid(rid);

       return  roleMapper.deleteByPrimaryKey(rid) ;
    }
}
